import 'package:flutter/material.dart';
import 'package:flutter_lib/utils/DpUtils.dart';
import 'package:flutter_lib/utils/ImageUtils.dart';
import 'package:flutter_my_web/bean/response/nginx_get_file_json_response.dart';
import 'package:flutter_my_web/constants/ConstantsUrlImage.dart';
import 'package:flutter_my_web/widget/ImageWidget.dart';
import 'package:flutter_my_web/widget/TextWidget.dart';

class FilePageItemWidget extends StatelessWidget {
  NginxGetFileJsonResponse bean;

  FilePageItemWidget(this.bean);

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        Container(
          width: 80.0.wDp,
          height: 80.0.wDp,
          padding: EdgeInsets.symmetric(horizontal: 10),
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(12),
            border: Border.all(
              color: bean.isDirectory ? Colors.yellow : Colors.blue,
              width: 1,
            ),
          ),
          child: contentWidget(),
        ),
        SimpleText(bean.name!),
        // SimpleSelectableText(bean.urlPath!),
      ],
    );
  }

  Widget contentWidget() {
    if (bean.isDirectory) {
      return Padding(
        padding: const EdgeInsets.all(8.0),
        child: Center(
          child: SizedBox(
              width: 50.0.wDp,
              height: 50.0.wDp,
              child: ImageLoadUtils(
                url: ConstantsUrlImage.iconDirectory,
                fit: BoxFit.contain,
              )),
        ),
      );
    }

    if (ImageUtils.isImage(bean.name!)) {
      return ImageLoadUtils(
        url: bean.urlPath,
        fit: BoxFit.contain,
      );
    }
    return Center(
      child: SizedBox(
          width: 50.0.wDp,
          height: 50.0.wDp,
          child: ImageLoadUtils(
            url: ConstantsUrlImage.iconFile,
            fit: BoxFit.contain,
          )),
    );
  }
}
